package com.ndhutu.ee.util.dwz.dw81;

import com.alibaba.fastjson.JSONObject;
import com.ndhutu.ee.util.http.OKHttpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author AppiJ
 * @Date 2020/9/8 18:06
 */
public class Dw81Util {

    final static String CREATE_API = "http://t.dw81.cn/dwz.php";

    /**
     * 创建短链接
     * @Author AppiJ
     * @Date 2020/9/8 18:08
     * @param
     * @return
     */
    public static  String createShortUrl(String longUrl) throws Exception{

        Map<String, String> params = new HashMap<String, String>();
        params.put("longurl", longUrl);
        params.put("dwzapi", "300");
        params.put("type", "qq");

        String resultJson = OKHttpUtil.get(CREATE_API, params);
        Map<String, Object> resultMap = (Map<String, Object>) JSONObject.parse(resultJson);


        return resultMap.get("ae_url").toString();
    }

    public static  String getShortUrl(String longUrl) throws Exception{
        Map<String, String> params = new HashMap<String, String>();
        params.put("longurl", longUrl);
        params.put("dwzapi", "111");
        params.put("type", "qq");

        String result = OKHttpUtil.get(CREATE_API, params);
        return result;
    }

    public static void main(String[] args) {
        try {
            System.out.println(getShortUrl("http://share.mm.jvtsydn.cn/invite/index.html?channelCode=&inviteCode=ST1925"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
